/*
* @Author: tomystery
* @Date:   2017-09-08 18:09:46
* @Last Modified by:   tomystery
* @Last Modified time: 2017-10-06 18:26:29
*/
'use strict';
require('./index.css');
var templateIndex=require('./index.string');
require('page/common/nav/index.js');
var navSide=require('page/common/nav-side/index.js');
require('page/common/header/index.js');

var _mm=require('util/mm.js');
var _order=require('service/order-service.js');


//page逻辑部分
var page={
	data:{
		orderNumber:_mm.getUrlParam('orderNumber')
	},
	init:function(){
		this.onLoad();
		this.bindEvent();
	},
	onLoad:function(){
		//初始化左侧菜单
		navSide.init({
			name:'order-list'
		});
		//加载用户信息
		this.loadOrderDetail();
	},
	//加载用户信息
	loadOrderDetail:function(){
		var _this=this;
		var orderListHtml='';
		var $listCon=$('.right-con');
		 $listCon.html('<div class="loading"></div>');
		_order.getOrderDetail(_this.data.orderNumber,function(res){
			  _this.dataFilter(res);
			//渲染html
			orderListHtml=_mm.renderHtml(templateIndex,res);
			$listCon.html(orderListHtml);
			
		},function(errMsg){
			_mm.errorTips(errMsg);
			$listCon.html('<p class="err-tip">加载订单详情失败，请刷新后重试</p>');
		});
	},
	bindEvent:function(){
		var _this=this;
		$(document).on('click', '.order-cancel', function(){

			if(window.confirm('确实要取消该订单？')){
                _order.orderCancel(_this.data.orderNumber, function(res){
                    _mm.successTips('该订单取消成功');
                    _this.loadOrderDetail();
                }, function(errMsg){
                    _mm.errorTips(errMsg);
                })
            }
		})
	},
	 // 数据的适配
    dataFilter : function(data){
        data.needPay        = data.status == 10;
        data.isCancelable   = data.status == 10;
    }
	
};
	

$(function(){
	page.init();
})
